﻿package communication1.pfl;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.sql.*;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
//import oracle.jdbc.driver.*;

/*import oracle.jdbc.driver.OracleDriver;*/
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.app.Service;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class Communication1Activity extends Activity {
	private String[] test_data = { "2222", "22222", "22222" };
	private Thread thread;
	private Thread thread2;
	private Thread thread3;
	private Handler handler;
	private GpsStatus gpsstatus;
	LocationManager locationManager;
	private ProgressBar jindu1;
	private ProgressBar jindu2;
	private ProgressBar jindu3;
	long jinduzhi1_max = 0;
	long jinduzhi1 = 0;
	long jinduzhi2_max = 0;
	long jinduzhi2 = 0;
	long jinduzhi3_max = 0;
	long jinduzhi3 = 0;
	int GPS = 0;
	private MySQLiteOpenHelper myOpenHelper;// 创建一个继承SQLiteOpenHelper类实例
	private SQLiteDatabase mysql;
	String currentProvider = "";
	// int jindutiao1=0;

	Location currentLocation = null;

	String jingdu = "0";
	String weidu = "0";
	String xianchang = "";
	String pic_zaihai = "";
	String vid_zaihai = "";
	String beizhu2 = "";

	String quanju_ip = "";
	String quanju_port = "";
	String quanju_ip2 = "";
	String quanju_port2 = "";

	String quanju_pc_ip = "";
	String quanju_pc_port = "";
	String quanju_database_ip = "";
	String quanju_database_port = "";
	String quanju_database_user = "";
	String quanju_database_psw = "";
	String quanju_database_service = "";

	String pic_name = "";
	String video_name = "";

	String pic_name2 = "";
	String video_name2 = "";
	String Number2;
	String zhaopianlujing2;
	String shipinlujing2;
	String zhaopianlujing;
	String shipinlujing;
	String rain;
	String wide;
	String undergrand;
	String safe;
	String beizhu;
	String jiancedian;
	String duankou;
	String[] jiancedianbianhao;
	String ip;
	String result = "";
	String result1 = "";
	String temp = "";
	Uri photoUri = null;
	Uri photoUri2 = null;
	int zongshu = 0;

	int count = 0;
	Spinner sp1;
	ArrayAdapter<String> adapter;
	List<String> allnum;

	private String[] arr = new String[1000];
	private String[] Value = new String[1000];

	String jiancedianhaoma = "123456789012345";

	int biaozhi = 0;// 总开关
	int flagt = 0;// 文字发送标识
	int flagp = 0;// 图片发送标识
	int flagv = 0;// 视频发送标识
	int flagp2 = 0;// 图片发送标识
	int flagv2 = 0;// 视频发送标识

	int count111 = 0;
	public static final int NONE = 0;
	public static final int PHOTOHRAPH = 4;// 拍照
	public static final int PHOTOHRAPH1 = 9;
	private static final int DIALOG = 99;
	private static final int DIALOG1 = 100;
	private static final int DIALOG10 = 101;
	private static final int DIALOG11 = 102;
	private static final int DIALOG12 = 103;
	private static final int DIALOG13 = 104;
	private static final int DIALOG14 = 105;
	private static final int DIALOG15 = 106;
	private static final int DIALOG16 = 107;
	private static final int DIALOG17 = 108;
	private TextView pda_no = null;
	Socket socket;// 创建全局socket

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main_v2);
		String path1 = Environment.getExternalStorageDirectory().toString()
				+ "/a1.jpg";
		String path2 = Environment.getExternalStorageDirectory().toString()
				+ "/a2.png";
		
		openGPSSettings();
		myOpenHelper = new MySQLiteOpenHelper(this);// 实例一个数据库辅助器
		mysql = myOpenHelper.getWritableDatabase(); // 实例数据库

		boolean cunzai;
		cunzai = tabbleIsExist("qunce1");
		if (cunzai == false) {

			String sqlbiao1 = "CREATE TABLE  qunce1(zaihai TEXT,jiance TEXT,jiancemingcheng TEXT);";
			mysql.execSQL(sqlbiao1);// 执行insert语句
			Toast.makeText(Communication1Activity.this, "监测点表不存在,初始化数据表",
					Toast.LENGTH_LONG).show();

		} else {
			// Toast.makeText(Communication1Activity.this,
			// "表已经存在",Toast.LENGTH_LONG).show();
		}

		boolean cunzai2;
		cunzai2 = tabbleIsExist("shezhi");
		if (cunzai2 == false) {

			String sqlbiao1 = "CREATE TABLE  shezhi(ip TEXT,port TEXT,database_ip TEXT,database_port TEXT,database_user TEXT,database_psw TEXT,database_service TEXT);";
			mysql.execSQL(sqlbiao1);// 执行insert语句
			mysql.execSQL("insert into shezhi(ip,port,database_ip,database_port,database_user,database_psw,database_service) values('127.0.0.1','8080','202.115.134.213','1521','sklgp','sklgp','orcl')");
			Toast.makeText(Communication1Activity.this, "配置表不存在,初始化数据表",
					Toast.LENGTH_LONG).show();

		} else {
			// Toast.makeText(Communication1Activity.this,
			// "表已经存在",Toast.LENGTH_LONG).show();
		}

		readdatabase();

		SpDemo();

		TelephonyManager phoneMgr = (TelephonyManager) this
				.getSystemService(Context.TELEPHONY_SERVICE);
		Number2 = phoneMgr.getDeviceId();

		locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
		currentProvider = locationManager.getProvider(
				LocationManager.GPS_PROVIDER).getName();
		currentLocation = locationManager.getLastKnownLocation(currentProvider);// 如果GPS信号较强，线程在此会阻塞
		locationManager.requestLocationUpdates(currentProvider, 10000, 10,
				locationListener);// 该方法用于注册监听器
		// locationManager.addGpsStatusListener(gpsListener);

		Button b44 = (Button) findViewById(R.id.get); // 抓取下载点按钮
		b44.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DIALOG13);
			}
		});

		Button b1 = (Button) findViewById(R.id.begin_record);
		b1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// jumpToLayout_cord();
				jump_record();

			}
		});
		// Button b4 = (Button) findViewById(R.id.up); //抓取升级软件按钮
		// b4.setOnClickListener(new View.OnClickListener() {
		// public void onClick(View v) {
		//
		// showDialog(78);
		// }
		// });
		Button b2 = (Button) findViewById(R.id.upload);
		b2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// showDialog(DIALOG14);
				// jumpToLayout_shangbao();
				jump_upload();
			}
		});
		/*
		 * Button b222 = (Button) findViewById(R.id.confi);
		 * b222.setOnClickListener(new View.OnClickListener() { public void
		 * onClick(View v) { showDialog(DIALOG15); } });
		 */
		EditText txt = (EditText) findViewById(R.id.edit2);
		//txt.setText(Number2);
		Button b245 = (Button) findViewById(R.id.setting);
		b245.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				jump_setting();
			}
		});
		// b245.setOnClickListener(new View.OnClickListener() {
		// public void onClick(View v) {
		// jumpToLayout_peizhi();
		// }
		// });
		
		pda_no = (TextView) findViewById(R.id.pda_no);
		pda_no.setText(String.format(getResources().getString(R.string.pda_str), "48748978978974878"));
		handler = new Handler() {
			/* @Override */
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case 0:
					Toast.makeText(Communication1Activity.this, "数据发送完成",
							Toast.LENGTH_LONG).show();
					break;
				case 1:
					Toast.makeText(Communication1Activity.this, "数据图片发送完成完成",
							Toast.LENGTH_LONG).show();
					break;
				case 2:
					Toast.makeText(Communication1Activity.this, "数据视频发送完成完成",
							Toast.LENGTH_LONG).show();
					break;
				case 3:
					Toast.makeText(Communication1Activity.this, "数据图片视频发送完成完成",
							Toast.LENGTH_LONG).show();
					break;
				case 4:
					Toast.makeText(Communication1Activity.this,
							"发送失败，请确认IP、端口设置是否正确并确保服务端接收软件是否正常",
							Toast.LENGTH_LONG).show();
					break;
				case 5:
					Toast.makeText(Communication1Activity.this, "未收到消息",
							Toast.LENGTH_LONG).show();
					break;
				case 6:
					Toast.makeText(Communication1Activity.this, "已经收到消息",
							Toast.LENGTH_LONG).show();
					break;
				case 7:
					Toast.makeText(Communication1Activity.this, "进入接收数据线程",
							Toast.LENGTH_LONG).show();
					break;
				case 8:
					Toast.makeText(Communication1Activity.this, "线程阻塞",
							Toast.LENGTH_LONG).show();
					break;
				case 55:
					Toast.makeText(Communication1Activity.this, "进入线程",
							Toast.LENGTH_LONG).show();
					break;
				case 56:
					Toast.makeText(Communication1Activity.this, result,
							Toast.LENGTH_LONG).show();
					break;
				case 57:
					Toast.makeText(
							Communication1Activity.this,
							"已经将" + Integer.toString(count111) + "条信息保存在手机数据库中",
							Toast.LENGTH_LONG).show();
					break;
				case 58:
					Toast.makeText(Communication1Activity.this, "操作失败",
							Toast.LENGTH_LONG).show();
					break;
				case 1033:
					Toast.makeText(Communication1Activity.this, "发送成功",
							Toast.LENGTH_LONG).show();
					break;
				case 1034:
					Toast.makeText(Communication1Activity.this, "发送失败，请先测试通信",
							Toast.LENGTH_LONG).show();
					break;
				case 59:
					Toast.makeText(Communication1Activity.this, "监测点更新完毕",
							Toast.LENGTH_LONG).show();
					// Toast.makeText(Communication1Activity.this,
					// "监测点更新完毕"+Value[0]+"_"+Value[1]+"_"+Value[2]+"_"+Value[3]+"_"+Value[4]+"_"+Value[5]+"_"+count,Toast.LENGTH_LONG).show();
					break;
				case 100:
					readdatabase();
					SpDemo();
					Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
					vib.vibrate(100);
					Toast.makeText(Communication1Activity.this, "监测点更新完毕",
							Toast.LENGTH_LONG).show();
					break;
				case 111:
					Toast.makeText(Communication1Activity.this, "定位中",
							Toast.LENGTH_LONG).show();
					break;
				case 112:

					Toast.makeText(Communication1Activity.this,
							"第一次定位完成:" + jingdu + "@@" + weidu,
							Toast.LENGTH_LONG).show();
					break;
				case 113:

					Toast.makeText(Communication1Activity.this,
							"监测点更新失败，请先测试通信", Toast.LENGTH_LONG).show();
					break;
				case 115:

					Toast.makeText(Communication1Activity.this, "下载完成",
							Toast.LENGTH_LONG).show();
					break;
				case 116:

					Toast.makeText(Communication1Activity.this, "下载失败",
							Toast.LENGTH_LONG).show();
					break;
				case 118:

					Toast.makeText(Communication1Activity.this,
							"SD卡不存在，请插入一张SD卡", Toast.LENGTH_LONG).show();
					break;

				case 119:

					jindu1.setProgress((int) jinduzhi1);
					Log.v("pfl", "更新一次进度条,jinduzhi1=" + (int) jinduzhi1);
					break;
				case 130:
					Toast.makeText(Communication1Activity.this, "测试通过",
							Toast.LENGTH_LONG).show();
					break;
				case 131:
					Toast.makeText(Communication1Activity.this,
							"测试失败，请检查服务器IP和端口是否设置正常，并保此网络畅通", Toast.LENGTH_LONG)
							.show();
					break;

				case 132:
					Toast.makeText(Communication1Activity.this,
							"与服务器连接成功，但是与数据库连接失败，请重新配置数据库", Toast.LENGTH_LONG)
							.show();
					break;
				default:
					break;
				}
			}
		};
		thread = new Thread(new Runnable()// 线程已经测试通过
				{
					/* @Override */
					public void run() {
						while (true) {
							if (biaozhi == 7)// 测试数据库
							{

								biaozhi = 0;
								/*
								 * Cursor guangbiao=
								 * mysql.rawQuery("select distinct * from shezhi"
								 * ,null);//执行Select语句 guangbiao.moveToNext();
								 * String a1=guangbiao.getString(0); String
								 * a2=guangbiao.getString(1);
								 */

								String response = ceshi2("http://"
										+ quanju_pc_ip + ":" + quanju_pc_port
										+ "/webreceiver/servlet/fileload");
								if (response.equals("ok")) {
									Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
									vib.vibrate(100);
									Message msg130 = new Message();
									msg130.what = 130;
									handler.sendMessage(msg130);

								} else {
									if (response.equals("no")) {
										Message msg132 = new Message();
										msg132.what = 132;
										handler.sendMessage(msg132);
									}

									else {
										Message msg131 = new Message();
										msg131.what = 131;
										handler.sendMessage(msg131);

									}
								}

							}

							if (biaozhi == 6)// 升级软件
							{
								biaozhi = 0;
								Cursor guangbiao = mysql.rawQuery(
										"select distinct * from shezhi", null);// 执行Select语句
								guangbiao.moveToNext();
								String a1 = guangbiao.getString(0);
								String a2 = guangbiao.getString(1);

								boolean response = shengji("http://" + a1 + ":"
										+ a2
										+ "/webreceiver/communication1.apk");
								if (response == true) {
									Log.v("pfl", "下载完成");
									Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
									vib.vibrate(100);
									Message msg115 = new Message();
									msg115.what = 115;
									handler.sendMessage(msg115);

								} else {
									Log.v("pfl", "下载失败");
									Message msg115 = new Message();
									msg115.what = 116;
									handler.sendMessage(msg115);
								}

							}

							if (biaozhi == 5)// 用于重新开启GPS定位的线程
							{

							}

							if (biaozhi == 4)// 用于测试通信
							{
								Log.v("pfl", "执行到此");
								biaozhi = 0;
								Cursor guangbiao = mysql.rawQuery(
										"select distinct * from shezhi", null);// 执行Select语句
								guangbiao.moveToNext();
								String a1 = guangbiao.getString(0);
								String a2 = guangbiao.getString(1);

								String response = ceshi("http://" + a1 + ":"
										+ a2 + "/webreceiver/servlet/fileload");
								if (response.equals("ok")) {
									Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
									vib.vibrate(100);
									Message msg130 = new Message();
									msg130.what = 130;
									handler.sendMessage(msg130);

								} else {
									Message msg131 = new Message();
									msg131.what = 131;
									handler.sendMessage(msg131);

								}
							}
							if (biaozhi == 3)// 开启灾害点上报线程
							{
								biaozhi = 0;
								if (xianchang.length() == 0) {
									xianchang = "未录入";
								}

								if (beizhu2.length() == 0) {
									beizhu2 = "未录入";
								}
								Cursor guangbiao = mysql.rawQuery(
										"select distinct * from shezhi", null);// 执行Select语句

								guangbiao.moveToNext();

								String a1 = guangbiao.getString(0);

								String a2 = guangbiao.getString(1);
								senddata2("http://" + a1 + ":" + a2
										+ "/webreceiver/servlet/fileload",
										pic_name, zhaopianlujing, video_name,
										shipinlujing);

							}
							if (biaozhi == 1)// 开启监测点信息上传线程
							{

								biaozhi = 0;

								if (rain.length() == 0) {
									rain = "未录入";
								}
								if (wide.length() == 0) {
									wide = "0";
								}
								if (undergrand.length() == 0) {
									undergrand = "未录入";
								}
								if (safe.length() == 0) {
									safe = "未录入";
								}
								if (beizhu.length() == 0) {
									beizhu = "未录入";
								}
								Cursor guangbiao = mysql.rawQuery(
										"select distinct * from shezhi", null);// 执行Select语句

								guangbiao.moveToNext();

								String a1 = guangbiao.getString(0);

								String a2 = guangbiao.getString(1);
								senddata("http://" + a1 + ":" + a2
										+ "/webreceiver/servlet/fileload",
										pic_name, zhaopianlujing, video_name,
										shipinlujing);

							}
							if (biaozhi == 9)// 下载启动标志
							{
								biaozhi = 0;
								Cursor guangbiao = mysql.rawQuery(
										"select distinct * from shezhi", null);// 执行Select语句

								guangbiao.moveToNext();

								String a1 = guangbiao.getString(0);

								String a2 = guangbiao.getString(1);

								String resp = download("http://" + a1 + ":"
										+ a2 + "/webreceiver/servlet/fileload",
										Number2);
								if (resp != "") {
									mysql.execSQL("delete from qunce1");
									try {
										Log.v("pfl", "qqqqqqq");
										String[] datass = resp
												.split("QWERTYUIOP");
										Log.v("pfl", "aaaaa");
										int lenth = datass.length;
										Log.v("pfl", "数组长度是：" + lenth);
										int ii = 0;
										for (String linshi : datass) {
											ii++;
											if (ii != 1) {
												String bianhao = linshi
														.substring(0, 16);
												String bianhao_name = linshi
														.substring(16);
												Log.v("pfl", bianhao + ":"
														+ bianhao_name);
												mysql.execSQL("INSERT INTO qunce1 (zaihai,jiance,jiancemingcheng) values ("
														+ (ii - 1)
														+ ",'"
														+ bianhao
														+ "','"
														+ bianhao_name + "')");

											}

										}

										Message msg4 = new Message();
										msg4.what = 100;
										handler.sendMessage(msg4); // 显示收到的信息

									} catch (Exception e) {
										Message msg = new Message();
										msg.what = 4;
										handler.sendMessage(msg);

									}
								} else {
									Message msg = new Message();
									msg.what = 113;
									handler.sendMessage(msg);
								}
							}
						}
					}
				});

		thread3 = new Thread(new Runnable()// 该线程用于进行GPS定位，会多次调用getlastdown函数
				{
					/* @Override */
					public void run() {

						Log.v("pfl", "线程GPS定位启动");

						if (GPS == 1) {
							GPS = 0;
							while (true)// 此句第一次用手机时，需要反复获取localtion，因此需要在线程中不断延时不断执行getLastKnownLocation
							{
								currentLocation = locationManager
										.getLastKnownLocation(currentProvider);
								// Log.d("pfl", "执行一次定位操作");
								if (currentLocation != null) {
									Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
									vib.vibrate(100);
									Message msg112 = new Message();
									msg112.what = 112;
									handler.sendMessage(msg112);
									jingdu = ""
											+ currentLocation.getLongitude();
									weidu = "" + currentLocation.getLatitude();
									break;// 注意此处会跳出while循环
								} else {
									/*
									 * Message msg111 = new Message();
									 * msg111.what=111;
									 * handler.sendMessage(msg111);
									 */

								}
								try {
									Thread.sleep(5000);
								} catch (InterruptedException e) {
									Log.e("Location", e.getMessage());
								}
							}
						}

					}
				});

		thread.start();

		thread3.start();
		GPS = 1;// 重新开启GPS定位
	}

	private boolean ExistSDCard() {
		if (android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			return true;
		} else
			return false;
	}

	private void installAPK(String apkUrl) {
		Log.v("pfl", "准备安装文件");
		Intent intent = new Intent(Intent.ACTION_VIEW);
		Log.v("pfl", "aaa");
		intent.setDataAndType(Uri.parse("file://" + apkUrl),
				"application/vnd.android.package-archive");
		Log.v("pfl", "bbb");
		startActivity(intent);// 安装
	}

	public void openGPSSettings() {
		LocationManager alm = (LocationManager) this
				.getSystemService(Context.LOCATION_SERVICE);
		if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
			// Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show();
			// getLocation();
			return;
		}

		Toast.makeText(this, "请开启GPS！", Toast.LENGTH_SHORT).show();
		Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
		startActivityForResult(intent, 0); // 此为设置完成后返回到获取界面

	}

	public GpsStatus.Listener gpsListener = new GpsStatus.Listener() {
		// GPS状态发生变化时触发
		@Override
		public void onGpsStatusChanged(int event) {
			// 获取当前状态
			gpsstatus = locationManager.getGpsStatus(null);
			switch (event) {
			// 第一次定位时的事件
			case GpsStatus.GPS_EVENT_FIRST_FIX:
				break;
			// 开始定位的事件
			case GpsStatus.GPS_EVENT_STARTED:
				break;
			// 发送GPS卫星状态事件
			case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
				Toast.makeText(Communication1Activity.this,
						"GPS_EVENT_SATELLITE_STATUS", Toast.LENGTH_SHORT)
						.show();
				Iterable<GpsSatellite> allSatellites = gpsstatus
						.getSatellites();
				Iterator<GpsSatellite> it = allSatellites.iterator();
				int count = 0;
				while (it.hasNext()) {
					count++;
				}
				Toast.makeText(Communication1Activity.this,
						"Satellite Count:" + count, Toast.LENGTH_SHORT).show();
				break;
			// 停止定位事件
			case GpsStatus.GPS_EVENT_STOPPED:
				Log.d("Location", "GPS_EVENT_STOPPED");
				break;
			}
		}
	};

	public LocationListener locationListener = new LocationListener() {
		// 位置发生改变时调用
		@Override
		public void onLocationChanged(Location location) {
			Log.d("pfl", "onLocationChanged");
			Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
			vib.vibrate(100);
			currentLocation = location;
			jingdu = "" + currentLocation.getLongitude();
			weidu = "" + currentLocation.getLatitude();
			Toast.makeText(Communication1Activity.this,
					"位置改变:" + jingdu + "@@" + weidu, Toast.LENGTH_LONG).show();
		}

		// provider失效时调用
		@Override
		public void onProviderDisabled(String provider) {
			Log.d("pfl", "onProviderDisabled");
			Toast.makeText(Communication1Activity.this, "GPS被关闭",
					Toast.LENGTH_LONG).show();
		}

		// provider启用时调用
		@Override
		public void onProviderEnabled(String provider) {
			Log.d("pfl", "onProviderEnabled");
			Toast.makeText(Communication1Activity.this, "GPS已经打开",
					Toast.LENGTH_LONG).show();
		}

		// 状态改变时调用
		@Override
		public void onStatusChanged(String provider, int status, Bundle extras) {
			Log.d("pfl", "onStatusChanged");
			Toast.makeText(Communication1Activity.this, "GPS状态改变",
					Toast.LENGTH_LONG).show();
		}
	};

	public boolean shengji(String urlStr) {

		String fileName = "communication1.apk";

		OutputStream output = null;
		try {

			URL url = new URL(urlStr);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();

			ContentValues values = new ContentValues(); // 创建一个内容提供者
			photoUri2 = Communication1Activity.this.getContentResolver()
					.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
							values);

			ContentResolver cr = this.getContentResolver();
			Cursor cursor = cr.query(photoUri2, null, null, null, null);
			cursor.moveToFirst(); // 游标移到第一条就是系统默认的路径
			String ceshi = "";
			if (cursor != null) {
				ceshi = cursor.getString(1); // 获取到的路径可以用于图片自定义压缩了
				cursor.close();
				Log.v("pfl", "临时生成的路径是：" + ceshi);
			}
			int k = ceshi.lastIndexOf("/");
			String linshishi = ceshi.substring(0, k);

			String pathName = linshishi + "/" + fileName;// 文件存储路径
			Log.v("pfl", "生成的路径是：" + pathName);

			Log.v("pfl", "准备创建apk文件");
			File file = new File(pathName);
			// Log.v("pfl","准备准备获取输入流");
			InputStream input = conn.getInputStream();
			// Log.v("pfl","获取成功");
			if (file.exists()) {
				Log.v("pfl", "文件存在");
				file.delete();
				Log.v("pfl", "删除文件成功");
				// return false;
			}

			Log.v("pfl", "开始创建apk文件");

			file.createNewFile();// 新建文件
			Log.v("pfl", "创建apk文件成功");
			output = new FileOutputStream(file);
			// 读取大文件
			int len;
			byte[] buffer = new byte[1024];

			while ((len = input.read(buffer)) != -1) {
				output.write(buffer, 0, len);
				Log.v("pfl", "下载到一点数据");
			}
			output.flush();
			output.close();

			installAPK(pathName);
			return true;
		}

		catch (Exception e) {
			return false;
		}

	}

	public String ceshi(String urlStr) {
		String resp = "";
		String end = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";
		try {
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			Log.v("pfl", "333333");
			/* 允许Input、Output，不使用Cache */
			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);
			/* 设置传送的method=POST */
			con.setRequestMethod("POST");
			/* setRequestProperty */
			con.setRequestProperty("Connection", "Keep-Alive");
			con.setRequestProperty("Charset", "UTF-8");
			con.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);
			con.connect();
			DataOutputStream ds = new DataOutputStream(con.getOutputStream());
			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"flag\""
					+ end + end);
			ds.writeBytes("00" + end);
			ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
			ds.flush();

			InputStream is = con.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream(), "UTF-8"));
			String ch;
			StringBuffer b = new StringBuffer();
			while ((ch = br.readLine()) != null) {
				b.append(ch);
			}
			Log.v("pfl", b.toString());
			ds.close();
			br.close();
			resp = b.toString();
		} catch (Exception e) {

		}

		return resp;
	}

	public String ceshi2(String urlStr) {
		String resp = "";
		String end = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";
		try {
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			Log.v("pfl", "333333");
			/* 允许Input、Output，不使用Cache */
			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);
			/* 设置传送的method=POST */
			con.setRequestMethod("POST");
			/* setRequestProperty */
			con.setRequestProperty("Connection", "Keep-Alive");
			con.setRequestProperty("Charset", "UTF-8");
			con.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);
			con.connect();
			DataOutputStream ds = new DataOutputStream(con.getOutputStream());
			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"flag\""
					+ end + end);
			ds.writeBytes("44" + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"quanju_database_ip\"" + end + end);
			ds.writeBytes(quanju_database_ip + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"quanju_database_port\"" + end + end);
			ds.writeBytes(quanju_database_port + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"quanju_database_user\"" + end + end);
			ds.writeBytes(quanju_database_user + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"quanju_database_psw\"" + end + end);
			ds.writeBytes(quanju_database_psw + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"quanju_database_service\"" + end + end);
			ds.writeBytes(quanju_database_service + end);
			ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
			ds.flush();

			InputStream is = con.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream(), "UTF-8"));
			String ch;
			StringBuffer b = new StringBuffer();
			while ((ch = br.readLine()) != null) {
				b.append(ch);
			}
			Log.v("pfl", b.toString());
			ds.close();
			br.close();
			resp = b.toString();
		} catch (Exception e) {

		}

		return resp;
	}

	public String download(String urlStr, String pdanumber) {
		String end = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";
		try {
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			Log.v("pfl", "333333");
			/* 允许Input、Output，不使用Cache */
			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);
			/* 设置传送的method=POST */
			con.setRequestMethod("POST");
			/* setRequestProperty */
			con.setRequestProperty("Connection", "Keep-Alive");
			con.setRequestProperty("Charset", "UTF-8");
			con.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);

			con.connect();
			/* 设置DataOutputStream */

			DataOutputStream ds = new DataOutputStream(con.getOutputStream());

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"flag\""
					+ end + end);
			ds.writeBytes("33" + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"Number2\"" + end + end);
			ds.writeBytes(pdanumber + end);
			ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
			ds.flush();
			Log.v("pfl", "准备接收数据");
			/* 取得Response内容 */
			InputStream is = con.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream(), "UTF-8"));
			String ch;

			StringBuffer b = new StringBuffer();

			while ((ch = br.readLine()) != null) {

				b.append(ch);

			}

			Log.v("pfl", b.toString());

			ds.close();
			br.close();
			return b.toString();
		} catch (Exception e) {
			return "";
		}
	}

	public void senddata(String urlStr, String serverFileName1, String path1,
			String serverFileName2, String path2) {
		jinduzhi1 = 0;
		if (flagp == 1 && flagv == 0) {
			File uploadFile1 = new File(path1);
			long size = (uploadFile1.length()) / 1024;
			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi1_max = size + 1;
		}
		if (flagp == 1 && flagv == 1) {
			File uploadFile1 = new File(path1);
			long size1 = (uploadFile1.length()) / 1024;

			File uploadFile2 = new File(path2);
			long size2 = (uploadFile2.length()) / 1024;

			long size = (size1 + size2);

			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi1_max = size + 2;
		}
		if (flagp == 0 && flagv == 1) {
			File uploadFile2 = new File(path2); // 不多讲
			long size = (uploadFile2.length()) / 1024;
			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi1_max = size + 1;
		}
		if (flagp == 0 && flagv == 0) {
			Log.v("pfl", "没有录入多媒体信息");
		}

		long shen = jinduzhi1_max * 6 / 5;
		long chazhi = jinduzhi1_max * 1 / 5;
		jinduzhi1_max = shen;
		jindu1.setMax((int) jinduzhi1_max);

		String end = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";
		try {
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			Log.v("pfl", "333333");

			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);

			con.setRequestMethod("POST");

			con.setRequestProperty("Connection", "Keep-Alive");
			con.setRequestProperty("Charset", "UTF-8");
			con.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);
			Log.v("pfl", "444");
			con.connect();

			Log.v("pfl", "555");
			DataOutputStream ds = new DataOutputStream(con.getOutputStream());
			Log.v("pfl", "666");

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"flag\""
					+ end + end);
			ds.writeBytes("11" + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"Number2\"" + end + end);
			ds.writeBytes(Number2 + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"jiancedianhaoma\"" + end + end);
			ds.writeBytes(jiancedianhaoma + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"rain\""
					+ end + end);
			ds.write(rain.getBytes());
			ds.writeBytes(end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"wide\""
					+ end + end);
			ds.write(wide.getBytes());
			ds.writeBytes(end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"undergrand\"" + end + end);
			ds.write(undergrand.getBytes());
			ds.writeBytes(end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"safe\""
					+ end + end);
			ds.write(safe.getBytes());
			ds.writeBytes(end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"beizhu\"" + end + end);
			ds.write(beizhu.getBytes());
			ds.writeBytes(end);

			if (flagp == 1) {
				flagp = 0;
				ds.writeBytes(twoHyphens + boundary + end);
				ds.writeBytes("Content-Disposition: form-data; "
						+ "name=\"picture\";filename=\"" + serverFileName1
						+ "\"" + end);
				ds.writeBytes(end);

				File uploadFile1 = new File(path1); // 不多讲
				FileInputStream fStream = new FileInputStream(uploadFile1);

				int bufferSize = 1024;
				byte[] buffer = new byte[bufferSize];
				int length = -1;

				while ((length = fStream.read(buffer)) != -1) {
					// Log.v("pfl","读取图片文件中,:"+length+"b");
					jindu1.setProgress((int) jinduzhi1);
					jinduzhi1++;
					Log.v("pfl", "jinduzhi1:" + (int) jinduzhi1);
					ds.write(buffer, 0, length);
				}
				fStream.close();
				ds.writeBytes(end);

			}
			if (flagv == 1) {
				flagv = 0;

				ds.writeBytes(twoHyphens + boundary + end);
				ds.writeBytes("Content-Disposition: form-data; "
						+ "name=\"vidio\";filename=\"" + serverFileName2 + "\""
						+ end);
				ds.writeBytes(end);
				/* 取得文件的FileInputStream */
				File uploadFile2 = new File(path2); // 不多讲
				FileInputStream fStream = new FileInputStream(uploadFile2);
				/* 设置每次写入1024bytes */
				int bufferSize = 1024;
				byte[] buffer = new byte[bufferSize];
				int length = -1;
				/* 从文件读取数据至缓冲区 */
				while ((length = fStream.read(buffer)) != -1) {
					// Log.v("pfl","读取视频文件中,:"+length+"b");
					jindu1.setProgress((int) jinduzhi1);
					jinduzhi1++;
					Log.v("pfl", "jinduzhi1:" + (int) jinduzhi1);
					/* 将资料写入DataOutputStream中 */
					ds.write(buffer, 0, length);
				}
				/* close streams */
				fStream.close();
			}
			ds.writeBytes(end);
			ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
			ds.flush();

			/* 取得Response内容 */
			InputStream is = con.getInputStream();
			Log.v("pfl", "获取输入流成功");
			int ch;
			StringBuffer b = new StringBuffer();
			Log.v("pfl", "创建缓存成功");
			while ((ch = is.read()) != -1) {
				b.append((char) ch);
				Log.v("pfl", "读取输入流一次");
			}
			Log.v("pfl", "读取完成：" + b);
			if (b.toString() != "") {
				jindu1.setProgress((int) (jinduzhi1 + chazhi));
				Message msg1033 = new Message();
				msg1033.what = 1033; // 插入数据库是否成功
				handler.sendMessage(msg1033);
				Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);

				vib.vibrate(100);
				jinduzhi1 = 0;
				jinduzhi1_max = 0;
			}
			/* 关闭DataOutputStream */

			ds.close();

		} catch (Exception e) {
			Message msg1034 = new Message();
			msg1034.what = 1034; // 插入数据库是否成功
			handler.sendMessage(msg1034);
			// Toast.makeText(getApplicationContext(),
			// e.getMessage().toString().trim(),Toast.LENGTH_SHORT).show();
		}
	}

	public void senddata2(String urlStr, String serverFileName1, String path1,
			String serverFileName2, String path2) {
		Log.v("pfl", "jingdu=" + jingdu);
		Log.v("pfl", "weidu=" + weidu);
		jinduzhi2 = 0;
		if (flagp2 == 1 && flagv2 == 0) {
			File uploadFile1 = new File(path1);
			long size = (uploadFile1.length()) / 1024;
			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi2_max = size + 1;
		}
		if (flagp2 == 1 && flagv2 == 1) {
			File uploadFile1 = new File(path1);
			long size1 = (uploadFile1.length()) / 1024;

			File uploadFile2 = new File(path2);
			long size2 = (uploadFile2.length()) / 1024;

			long size = (size1 + size2);

			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi2_max = size + 2;
		}
		if (flagp2 == 0 && flagv2 == 1) {
			File uploadFile2 = new File(path2); // 不多讲
			long size = (uploadFile2.length()) / 1024;
			Log.v("pfl", "max长度是：" + (Long.toString(size)));
			jinduzhi2_max = size + 1;
		}
		if (flagp2 == 0 && flagv2 == 0) {

		}
		long shen = jinduzhi2_max * 6 / 5;
		long chazhi = jinduzhi2_max * 1 / 5;
		jinduzhi2_max = shen;

		jindu2.setMax((int) jinduzhi2_max);
		String end = "\r\n";
		String twoHyphens = "--";
		String boundary = "*****";
		try {
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			Log.v("pfl", "333333");

			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);

			con.setRequestMethod("POST");

			con.setRequestProperty("Connection", "Keep-Alive");
			con.setRequestProperty("Charset", "UTF-8");
			con.setRequestProperty("Content-Type",
					"multipart/form-data;boundary=" + boundary);
			Log.v("pfl", "444");
			con.connect();

			Log.v("pfl", "555");
			DataOutputStream ds = new DataOutputStream(con.getOutputStream());
			Log.v("pfl", "666");

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"flag\""
					+ end + end);
			ds.writeBytes("22" + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"Number2\"" + end + end);
			ds.writeBytes(Number2 + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"jingdu\"" + end + end);
			ds.writeBytes(jingdu + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; " + "name=\"weidu\""
					+ end + end);
			ds.writeBytes(weidu + end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"xianchang\"" + end + end);
			ds.write(xianchang.getBytes());
			ds.writeBytes(end);

			ds.writeBytes(twoHyphens + boundary + end);
			ds.writeBytes("Content-Disposition: form-data; "
					+ "name=\"beizhu2\"" + end + end);
			ds.write(beizhu2.getBytes());
			ds.writeBytes(end);

			if (flagp2 == 1) {
				flagp2 = 0;
				ds.writeBytes(twoHyphens + boundary + end);
				ds.writeBytes("Content-Disposition: form-data; "
						+ "name=\"picture\";filename=\"" + serverFileName1
						+ "\"" + end);
				ds.writeBytes(end);

				File uploadFile1 = new File(path1); // 不多讲
				FileInputStream fStream = new FileInputStream(uploadFile1);

				int bufferSize = 1024;
				byte[] buffer = new byte[bufferSize];
				int length = -1;

				while ((length = fStream.read(buffer)) != -1) {
					// Log.v("pfl","读取图片文件中");
					jindu2.setProgress((int) jinduzhi2);
					jinduzhi2++;
					Log.v("pfl", "jinduzhi2:" + (int) jinduzhi2);
					ds.write(buffer, 0, length);
				}
				fStream.close();
				ds.writeBytes(end);

			}
			if (flagv2 == 1) {
				flagv2 = 0;
				ds.writeBytes(twoHyphens + boundary + end);
				ds.writeBytes("Content-Disposition: form-data; "
						+ "name=\"vidio\";filename=\"" + serverFileName2 + "\""
						+ end);
				ds.writeBytes(end);
				/* 取得文件的FileInputStream */
				File uploadFile2 = new File(path2); // 不多讲
				FileInputStream fStream = new FileInputStream(uploadFile2);
				/* 设置每次写入1024bytes */
				int bufferSize = 1024;
				byte[] buffer = new byte[bufferSize];
				int length = -1;
				/* 从文件读取数据至缓冲区 */
				while ((length = fStream.read(buffer)) != -1) {
					// Log.v("pfl","读取视频文件中");
					/* 将资料写入DataOutputStream中 */
					jindu2.setProgress((int) jinduzhi2);
					jinduzhi2++;
					Log.v("pfl", "jinduzhi2:" + (int) jinduzhi2);
					ds.write(buffer, 0, length);
				}
				/* close streams */
				fStream.close();
			}
			ds.writeBytes(end);
			ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
			ds.flush();

			/* 取得Response内容 */
			InputStream is = con.getInputStream();
			Log.v("pfl", "获取输入流成功");
			int ch;
			StringBuffer b = new StringBuffer();
			Log.v("pfl", "创建缓存成功");
			while ((ch = is.read()) != -1) {
				b.append((char) ch);
				Log.v("pfl", "读取输入流一次");
			}
			Log.v("pfl", "读取完成：" + b);
			if (b.toString() != "") {
				jindu2.setProgress((int) (jinduzhi2 + chazhi));
				Message msg1033 = new Message();
				msg1033.what = 1033; // 插入数据库是否成功
				handler.sendMessage(msg1033);
				Vibrator vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);

				vib.vibrate(100);
				jinduzhi2 = 0;
				jinduzhi2_max = 0;
			}
			/* 关闭DataOutputStream */

			ds.close();

		} catch (Exception e) {
			Message msg1034 = new Message();
			msg1034.what = 1034; // 插入数据库是否成功
			handler.sendMessage(msg1034);
			// Toast.makeText(getApplicationContext(),
			// e.getMessage().toString().trim(),Toast.LENGTH_SHORT).show();
		}
	}

	private void SpDemo() // 将数据库中的信息装载进下拉列表
	{

		sp1 = (Spinner) findViewById(R.id.sp1);
//		adapter = new ArrayAdapter<String>(this,
//				android.R.layout.simple_spinner_item);
//		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//		int g = 0;
//		for (g = 0; g < zongshu; g++) {
//			Log.v("pfl", "加载一次数据");
//			adapter.add(arr[g]);
//
//		}
//		sp1.setOnClickListener(new View.OnClickListener() {
//
//			@Override
//			public void onClick(View arg0) {
//				// TODO Auto-generated method stub
//				showDialog();
//			}
//		});
//		try {
//			sp1.setAdapter(adapter);
//			Log.v("pfl", "最后一步成功");
//		} catch (Exception e) {
//			Log.v("pfl", "最后一步出现错误：" + e.getMessage().toString());
//		}
//		Log.v("pfl", "加载完成");
//		sp1.setOnItemSelectedListener(new OnItemSelectedListener() {
//			public void onItemSelected(AdapterView<?> arg0, View arg1,
//					int arg2, long arg3) {
//
//				jiancedianhaoma = Value[arg2];
//				// Toast.makeText(Communication1Activity.this,
//				// Value[arg2],10).show();
//			}
//
//			public void onNothingSelected(AdapterView<?> arg0) {
//			}
//		});
	}

	public void readdatabase()// 从数据库中读取信息进数据
	{
		Cursor guangbiao = mysql
				.rawQuery("select distinct * from qunce1", null);// 执行Select语句
		int u = 0;
		while (guangbiao.moveToNext()) //
		{
			Value[u] = guangbiao.getString(1); // Value指监测点编号

			arr[u] = guangbiao.getString(2); // arr指监测点汉字
			u++;
		}
		zongshu = u;

	}

	public boolean tabbleIsExist(String tableName) {
		boolean result = false;
		if (tableName == null) {
			return false;
		}
		// SQLiteDatabase db = null;
		Cursor cursor = null;
		try {
			// db = this.getReadableDatabase();
			String sql = "select count(*) as c from Sqlite_master  where type ='table' and name ='"
					+ tableName.trim() + "' ";
			cursor = mysql.rawQuery(sql, null);
			if (cursor.moveToNext()) {
				int count = cursor.getInt(0);
				if (count > 0) {
					result = true;
				}
			}

		} catch (Exception e) {
			// TODO: handle exception
		}
		return result;
	}

	public void jumpToLayout_main()// 主界面 只要跳转到该页面，就会清空录入数据
	{
		// 清空所有数据
		zhaopianlujing = "";
		shipinlujing = "";
		rain = "";
		wide = "";
		undergrand = "";
		safe = "";
		beizhu = "";
		jiancedian = "";
		jiancedianhaoma = "123456789012345";
		xianchang = "";
		beizhu2 = "";
		jingdu = "0";
		weidu = "0";

		flagp = 0;
		flagp2 = 0;
		flagv2 = 0;
		flagv = 0;

		setContentView(R.layout.main);
		Log.v("pfl", "准备读取数据库");
		readdatabase();
		Log.v("pfl", "准备加载数据进下拉表");
		SpDemo();
		Log.v("pfl", "加载完成");
		Button b1 = (Button) findViewById(R.id.begin_record);
		b1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// jumpToLayout_cord();
				jump_record();
			}
		});

		Button b44 = (Button) findViewById(R.id.get); // 抓取下载点按钮
		b44.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DIALOG13);

			}
		});
		Button b4 = (Button) findViewById(R.id.up); // 抓取升级软件按钮
		b4.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				showDialog(78);
			}
		});
		/*
		 * Button b2222 = (Button) findViewById(R.id.confi);
		 * b2222.setOnClickListener(new View.OnClickListener() { public void
		 * onClick(View v) { showDialog(DIALOG15); } });
		 */
		Button b2 = (Button) findViewById(R.id.upload);
		b2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				// jumpToLayout_shangbao();
				jump_upload();
			}
		});

		Button b245 = (Button) findViewById(R.id.setting);
		b245.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// jumpToLayout_peizhi();
				jump_setting();
			}
		});
		EditText txt = (EditText) findViewById(R.id.edit2);
		txt.setText(Number2);
	}

	public void jump_setting() {
		Intent intent = new Intent(this, SettingActivity.class);
		startActivity(intent);
	}

	public void jumpToLayout_peizhi() {
		setContentView(R.layout.peizhi);
		{
			Button b1 = (Button) findViewById(R.id.return2);// 返回
			b1.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					jumpToLayout_main();
				}
			});
		}

		{
			Button b1 = (Button) findViewById(R.id.test_server);// 测试服务器
			b1.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					showDialog(88);

				}
			});
		}

		{
			Button b1 = (Button) findViewById(R.id.test_database);// 测试数据库
			b1.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					showDialog(89);
				}
			});
		}

		Cursor guangbiao = mysql
				.rawQuery("select distinct * from shezhi", null);// 执行Select语句
		Log.v("pfl", "准备查询配置表");
		String pc_ip = "";
		String pc_port = "";
		String database_ip = "";
		String database_port = "";
		String database_user = "";
		String database_psw = "";
		String database_service = "";

		if (guangbiao.moveToNext() == true)
			;
		{
			Log.v("pfl", "查询到数据");
			pc_ip = guangbiao.getString(0);
			pc_port = guangbiao.getString(1);

			database_ip = guangbiao.getString(2);
			database_port = guangbiao.getString(3);
			database_user = guangbiao.getString(4);
			database_psw = guangbiao.getString(5);
			database_service = guangbiao.getString(6);
		}
		Log.v("pfl", "查询完成");

		EditText txt1 = (EditText) findViewById(R.id.pc_ip);
		txt1.setText(pc_ip);

		EditText txt2 = (EditText) findViewById(R.id.pc_port);
		txt2.setText(pc_port);

		EditText txt3 = (EditText) findViewById(R.id.database_ip);
		txt3.setText(database_ip);

		EditText txt4 = (EditText) findViewById(R.id.database_port);
		txt4.setText(database_port);

		EditText txt5 = (EditText) findViewById(R.id.database_user);
		txt5.setText(database_user);

		EditText txt6 = (EditText) findViewById(R.id.database_psw);
		txt6.setText(database_psw);

		EditText txt7 = (EditText) findViewById(R.id.database_service);
		txt7.setText(database_service);

	}

	public void jump_upload() {
		Intent intent = new Intent(this, UploadActivity.class);
		startActivity(intent);
	}

	public void jump_record() {
		Intent intent = new Intent(this, RecordActivity.class);
		startActivity(intent);
	}

	public void jumpToLayout_cord()// 进入信息录入界面
	{
		setContentView(R.layout.record_v2);
		// Toast.makeText(Communication1Activity.this,
		// "缝宽项请输入数字信息",Toast.LENGTH_LONG).show();
		Button b1 = (Button) findViewById(R.id.back);// 返回
		b1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				jumpToLayout_main();
			}
		});
		EditText e1 = (EditText) findViewById(R.id.edit7);
		e1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// Toast.makeText(Communication1Activity.this,
				// "请输入数字信息",Toast.LENGTH_LONG).show();
			}
		});
		Button b2 = (Button) findViewById(R.id.next); // 下一步
		b2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				EditText txt1 = (EditText) findViewById(R.id.edit6);
				rain = txt1.getText().toString();
				EditText txt2 = (EditText) findViewById(R.id.edit7);
				wide = txt2.getText().toString();
				EditText txt3 = (EditText) findViewById(R.id.edit8);
				undergrand = txt3.getText().toString();
				EditText txt4 = (EditText) findViewById(R.id.edit9);
				safe = txt4.getText().toString();

				Pattern pattern = Pattern.compile("^[0-9]*$");
				Matcher matcher = pattern.matcher(wide);
				boolean b = matcher.matches();
				if (b == true) {
					jumpToLayout_send();
				} else {

					Toast.makeText(Communication1Activity.this,
							"裂缝宽度请输入数字，不能有中文和字母！", Toast.LENGTH_LONG).show();
				}
			}
		});
		Button bb1 = (Button) findViewById(R.id.b1); // 雨量设置
		bb1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DIALOG);
			}
		});
		Button bb2 = (Button) findViewById(R.id.b2); // 缝宽设置
		bb2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// ///////////////////////
			}
		});
		Button bb3 = (Button) findViewById(R.id.b3); // 地下水动态
		bb3.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DIALOG1);
			}
		});
		Button bb4 = (Button) findViewById(R.id.b4); // 危险度等级
		bb4.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DIALOG10);
			}
		});
		Button bb5 = (Button) findViewById(R.id.b5); // 照片
		bb5.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				Intent imageCaptureIntent = new Intent(
						MediaStore.ACTION_IMAGE_CAPTURE);
				ContentValues values = new ContentValues(); // 创建一个内容提供者
				photoUri = Communication1Activity.this.getContentResolver()
						.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
								values);
				imageCaptureIntent.putExtra(
						android.provider.MediaStore.EXTRA_OUTPUT, photoUri);
				startActivityForResult(imageCaptureIntent, PHOTOHRAPH);

			}
		});
		Button bb6 = (Button) findViewById(R.id.b6); // 录像
		bb6.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

				Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
				intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
				startActivityForResult(intent, PHOTOHRAPH1);

			}
		});
	}

	public void jumpToLayout_shangbao()// 进入信息上报界面
	{
		setContentView(R.layout.shangbao);
		jindu2 = (ProgressBar) findViewById(R.id.jindu2);
		Button b1 = (Button) findViewById(R.id.backmain);// 返回
		b1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				jumpToLayout_main();
			}
		});

		Button b3 = (Button) findViewById(R.id.pic2);
		b3.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent imageCaptureIntent = new Intent(
						MediaStore.ACTION_IMAGE_CAPTURE);
				ContentValues values = new ContentValues(); // 创建一个内容提供者
				photoUri = Communication1Activity.this.getContentResolver()
						.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
								values);

				Log.v("pfl", "路径是：" + photoUri.getPath());
				imageCaptureIntent.putExtra(
						android.provider.MediaStore.EXTRA_OUTPUT, photoUri);
				startActivityForResult(imageCaptureIntent, PHOTOHRAPH);

			}
		});
		Button b4 = (Button) findViewById(R.id.vid2);
		b4.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
				intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);

				startActivityForResult(intent, PHOTOHRAPH1);
			}
		});

		Button b2 = (Button) findViewById(R.id.beginshangbao);
		b2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				EditText txt = (EditText) findViewById(R.id.xianchang);
				xianchang = txt.getText().toString();

				EditText txt1 = (EditText) findViewById(R.id.beizhu2);
				beizhu2 = txt1.getText().toString();

				Log.v("pfl", "xianchang:" + xianchang);
				Log.v("pfl", "beizhu2:" + beizhu2);
				showDialog(DIALOG17);
			}
		});

		Button b32 = (Button) findViewById(R.id.finish_shangbao);
		b32.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				jumpToLayout_main();
			}
		});
	}

	public void jumpToLayout_send()// 进入信息发送界面
	{
		setContentView(R.layout.send);
		jindu1 = (ProgressBar) findViewById(R.id.jindu1);
		Button b1 = (Button) findViewById(R.id.back1);
		b1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				jumpToLayout_cord();
			}
		});
		Button b2 = (Button) findViewById(R.id.finish);
		b2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				jumpToLayout_main();
				zhaopianlujing = "";
				shipinlujing = "";
				rain = "";
				wide = "";
				undergrand = "";
				safe = "";
				beizhu = "";
				jiancedian = "";
				jiancedianhaoma = "123456789012345";
			}
		});

		Button b3 = (Button) findViewById(R.id.begin_send);
		b3.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				EditText txt = (EditText) findViewById(R.id.edit12);
				beizhu = txt.getText().toString();
				showDialog(DIALOG12);
			}
		});
	}

	public static boolean saveImage(Bitmap photo, String spath) {
		try {
			BufferedOutputStream bos = new BufferedOutputStream(
					new FileOutputStream(spath, false));
			photo.compress(Bitmap.CompressFormat.JPEG, 100, bos);
			bos.flush();
			bos.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public byte[] getBitmapByte(Bitmap bitmap) {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
		try {
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return out.toByteArray();
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_MENU) {// 拦截menu键事件
			// do something...
			// System.exit(0);

		}

		if (keyCode == KeyEvent.KEYCODE_BACK) {// 拦截返回按钮事件
			showDialog(DIALOG14);
		}
		return true;
	}

	/* @Override */
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode == NONE)
			return;
		if (requestCode == PHOTOHRAPH) {
			if (resultCode == RESULT_OK) {

				flagp = 1;
				flagp2 = 1;
				Log.v("pfl", "准备获取数据:" + data);

				ContentResolver cr = this.getContentResolver();
				Cursor cursor = cr.query(photoUri, null, null, null, null);
				cursor.moveToFirst(); // 游标移到第一条就是系统默认的路径
				if (cursor != null) {
					zhaopianlujing = cursor.getString(1); // 获取到的路径可以用于图片自定义压缩了
					cursor.close();
					Log.v("pfl", "照片路径是：" + zhaopianlujing);
				}

				pic_name = new SimpleDateFormat("yyyyMMddHHmmss")
						.format(new Date()) + ".jpg";// 照片命名

				try {
					EditText txt = (EditText) findViewById(R.id.edit10);
					txt.setText("已拍照");
				} catch (Exception e) {

				}
				try {
					EditText txt1 = (EditText) findViewById(R.id.pic2_text);
					txt1.setText("已拍照");
				} catch (Exception e) {

				}
			}
		}
		if (requestCode == PHOTOHRAPH1) {
			if (resultCode == RESULT_OK) {
				flagv = 1;
				flagv2 = 1;
				Uri uriVideo = data.getData();
				Cursor cursor = this.getContentResolver().query(uriVideo, null,
						null, null, null);
				if (cursor.moveToNext()) // 实际只查询了一次
				{
					shipinlujing = cursor.getString(cursor
							.getColumnIndex("_data"));
					video_name = new SimpleDateFormat("yyyyMMddHHmmss")
							.format(new Date()) + ".3gp";
				}

				try {
					EditText txt = (EditText) findViewById(R.id.edit11);
					txt.setText("已摄像");
				} catch (Exception e) {

				}
				try {
					EditText txt1 = (EditText) findViewById(R.id.vid2_text);
					txt1.setText("已摄像");
				} catch (Exception e) {

				}

			}
		}
	}

	protected Dialog onCreateDialog(int id) {
		final CharSequence[] items = { "无雨", "小雨", "中雨", "大雨", "暴雨" };
		final CharSequence[] items1 = { "无水", "渗水", "浸水", "冒水", "流水" };
		final CharSequence[] items2 = { "低危险度", "中危险度", "高危险度" };
		final CharSequence[] items3 = { "裂缝监测点2#-520422010001QJ03",
				"裂缝监测点1#-520121020001QJ02", "裂缝监测点1#-520422010001QJ02",
				"墙裂缝2#-522325010087QJ02", "泉点1#-522325010087QJ03",
				"裂缝监测点1#-522325010087QJ01" };
		final CharSequence[] items4 = { "本机测试-172.19.10.164-8080",
				"5256服务器-202.115.132.202-8080", "318服务器-202.115.134.213-1456",
				"318服务器-202.115.134.213-1567", "318服务器-202.115.134.213-1789" };
		Dialog dialog = null;
		switch (id) {
		case DIALOG:
			Builder builder = new android.app.AlertDialog.Builder(this);
			builder.setTitle("降雨情况");
			builder.setSingleChoiceItems(items, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int item) {
							EditText txt1 = (EditText) findViewById(R.id.edit6);
							txt1.setText(items[item]);
						}
					});
			builder.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						}
					});
			dialog = builder.create();
			break;
		case DIALOG1:
			Builder builder1 = new android.app.AlertDialog.Builder(this);
			builder1.setTitle("地下水动态");
			builder1.setSingleChoiceItems(items1, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int item) {

							EditText txt2 = (EditText) findViewById(R.id.edit8);
							txt2.setText(items1[item]);
						}
					});
			builder1.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						}
					});
			dialog = builder1.create();
			break;
		case DIALOG10: // 发送数据信息
			Builder builder2 = new android.app.AlertDialog.Builder(this);
			builder2.setTitle("危险度等级");
			builder2.setSingleChoiceItems(items2, -1,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int item) {

							EditText txt1 = (EditText) findViewById(R.id.edit9);
							txt1.setText(items2[item]);
						}
					});
			builder2.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						}
					});
			dialog = builder2.create();
			break;

		case DIALOG12:
			Builder builder6 = new android.app.AlertDialog.Builder(this);
			builder6.setTitle("确定要发送信息吗？");

			builder6.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							biaozhi = 1;

							// Toast.makeText(Communication1Activity.this,
							// "开始发送信息，请勿关闭软件",Toast.LENGTH_LONG).show();
						}
					});
			builder6.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder6.create();
			break;
		case DIALOG13:
			Builder builder32 = new android.app.AlertDialog.Builder(this);

			builder32.setTitle("确定要更新监测点吗？");

			builder32.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

							biaozhi = 9;
						}
					});
			builder32.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder32.create();

			break;
		case DIALOG14:
			Builder builder14 = new android.app.AlertDialog.Builder(this);
			builder14.setTitle("确定要退出软件吗？");

			builder14.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							android.os.Process.killProcess(android.os.Process
									.myPid());
							System.exit(0);
						}
					});
			builder14.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder14.create();
			break;
		case DIALOG15:
			Cursor guangbiao = mysql.rawQuery("select distinct * from shezhi",
					null);// 执行Select语句
			Log.v("pfl", "准备查询配置表");
			if (guangbiao.moveToNext() == true)
				;
			{
				Log.v("pfl", "查询到数据");
				quanju_ip2 = guangbiao.getString(0);

				quanju_port2 = guangbiao.getString(1);
			}
			Log.v("pfl", "查询完成");
			final EditText inputIP = new EditText(this);
			inputIP.setText(quanju_ip2);

			Builder builder15 = new android.app.AlertDialog.Builder(this);
			builder15.setTitle("请填写IP");
			builder15.setView(inputIP);

			builder15.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							String inputName = inputIP.getText().toString();
							quanju_ip = inputName;
							// Toast.makeText(Communication1Activity.this,
							// inputName,Toast.LENGTH_LONG).show();
							showDialog(DIALOG16);
						}
					});

			dialog = builder15.create();

			break;
		case DIALOG16:
			final EditText inputPORT = new EditText(this);
			inputPORT.setText(quanju_port2);
			Builder builder16 = new android.app.AlertDialog.Builder(this);
			builder16.setTitle("请填写端口");
			builder16.setView(inputPORT);

			builder16.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							String inputName = inputPORT.getText().toString();
							quanju_port = inputName;

							mysql.execSQL("delete from shezhi");

							mysql.execSQL("insert into shezhi(ip,port) values('"
									+ quanju_ip + "','" + quanju_port + "')");

							// Toast.makeText(Communication1Activity.this,
							// "设置保存",Toast.LENGTH_LONG).show();
							biaozhi = 4;
						}
					});
			dialog = builder16.create();
			break;
		case DIALOG17:
			Builder builder17 = new android.app.AlertDialog.Builder(this);
			builder17.setTitle("确定要上报信息吗？");

			builder17.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							biaozhi = 3;// 开启灾害点上报线程

						}
					});
			builder17.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder17.create();
			break;
		case 78: // 升级软件
			Builder builder78 = new android.app.AlertDialog.Builder(this);
			builder78.setTitle("确定要升级软件吗？");

			builder78.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							biaozhi = 6;

						}
					});
			builder78.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder78.create();
			break;
		case 88: //
			Builder builder88 = new android.app.AlertDialog.Builder(this);
			builder88.setTitle("确定要测试服务器吗？");

			builder88.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							String pc_ip = "";
							String pc_port = "";
							String database_ip = "";
							String database_port = "";
							String database_user = "";
							String database_psw = "";
							String database_service = "";

							EditText txt1 = (EditText) findViewById(R.id.pc_ip);
							pc_ip = txt1.getText().toString();

							EditText txt2 = (EditText) findViewById(R.id.pc_port);
							pc_port = txt2.getText().toString();

							EditText txt3 = (EditText) findViewById(R.id.database_ip);
							database_ip = txt3.getText().toString();

							EditText txt4 = (EditText) findViewById(R.id.database_port);
							database_port = txt4.getText().toString();

							EditText txt5 = (EditText) findViewById(R.id.database_user);
							database_user = txt5.getText().toString();

							EditText txt6 = (EditText) findViewById(R.id.database_psw);
							database_psw = txt6.getText().toString();

							EditText txt7 = (EditText) findViewById(R.id.database_service);
							database_service = txt7.getText().toString();

							quanju_ip = pc_ip;
							quanju_port = pc_port;
							mysql.execSQL("delete from shezhi");

							mysql.execSQL("insert into shezhi(ip,port,database_ip,database_port,database_user,database_psw,database_service) values('"
									+ pc_ip
									+ "','"
									+ pc_port
									+ "','"
									+ database_ip
									+ "','"
									+ database_port
									+ "','"
									+ database_user
									+ "','"
									+ database_psw
									+ "','"
									+ database_service
									+ "')");

							biaozhi = 4;

						}
					});
			builder88.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder88.create();
			break;

		case 89: //
			Builder builder89 = new android.app.AlertDialog.Builder(this);
			builder89.setTitle("确定要测试数据库吗？");

			builder89.setPositiveButton(" 确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							String pc_ip = "";
							String pc_port = "";
							String database_ip = "";
							String database_port = "";
							String database_user = "";
							String database_psw = "";
							String database_service = "";

							EditText txt1 = (EditText) findViewById(R.id.pc_ip);
							pc_ip = txt1.getText().toString();

							EditText txt2 = (EditText) findViewById(R.id.pc_port);
							pc_port = txt2.getText().toString();

							EditText txt3 = (EditText) findViewById(R.id.database_ip);
							database_ip = txt3.getText().toString();

							EditText txt4 = (EditText) findViewById(R.id.database_port);
							database_port = txt4.getText().toString();

							EditText txt5 = (EditText) findViewById(R.id.database_user);
							database_user = txt5.getText().toString();

							EditText txt6 = (EditText) findViewById(R.id.database_psw);
							database_psw = txt6.getText().toString();

							EditText txt7 = (EditText) findViewById(R.id.database_service);
							database_service = txt7.getText().toString();

							quanju_pc_ip = pc_ip;
							quanju_pc_port = pc_port;
							quanju_database_ip = database_ip;
							quanju_database_port = database_port;
							quanju_database_user = database_user;
							quanju_database_psw = database_psw;
							quanju_database_service = database_service;

							mysql.execSQL("delete from shezhi");

							mysql.execSQL("insert into shezhi(ip,port,database_ip,database_port,database_user,database_psw,database_service) values('"
									+ pc_ip
									+ "','"
									+ pc_port
									+ "','"
									+ database_ip
									+ "','"
									+ database_port
									+ "','"
									+ database_user
									+ "','"
									+ database_psw
									+ "','"
									+ database_service
									+ "')");

							biaozhi = 7;

						}
					});
			builder89.setNegativeButton("取消",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			dialog = builder89.create();
			break;
		}
		return dialog;
	}

	public void showDialog() {
		new AlertDialog.Builder(this).setTitle("请选择监测点")
				.setItems(test_data, new OnClickListener() {

					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						Toast.makeText(Communication1Activity.this,
								"您选择了:" + test_data[arg1] + "",
								Toast.LENGTH_SHORT).show();
					}
				}).create().show();
	}
}